const h = (function () {
  return {
    getCookieAll: function () {
      // 1.取出所有的cookie数据
      var strCookie = document.cookie; //age=18; height=190
      // 2.拼成一个对象
      var arrCookie = strCookie.split('; ');//[age=18; height=190]
      // 3.创建一个空对象
      var objCookie = {};
      for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split('=') //[age,18] [height,190]
        var key = arr[0]
        var value = arr[1]
        objCookie[key] = value;
      }
      return objCookie
    },
    getCookie: function (name) {
      return this.getCookieAll()[name]
    },
    setCookie: function (name, value, expires, path, domain, secure) {
      var strhtml = '';
      if (name) {
        strhtml += `${name}=${value};`
      }
      if (typeof (expires) == 'number') {
        var date = new Date();
        date.setDate(date.getDate() + expires);
        strhtml += `expires=${date};`
      }
      if (path) {
        strhtml += `path=${path};`
      }
      if (domain) {
        strhtml += `domain=${domain};`
      }
      if (secure) {
        strhtml += `secure`
      }
      document.cookie = strhtml;
    },
    removeCookie: function (name) {
      this.setCookie(name, '', -1)
    }
  }
})()